#include <iostream>
#include <stdlib.h>
#include <algorithm>

using namespace std;

int testlen(int targetlen);
bool concated(int leftlen, int targetlen, int usednum);

//int compare(const void* a, const void* b) {
//    int r = *(int*) a - *(int*) b;
//    if (r > 0) {
//        return 1;
//    }
//    return 0;
//}

int stick[64];
int used[64];
int num;

int main() {
    cin >> num;
    while (num) {
        int sum = 0;
        for (int i = 0; i < num; i++) {
            cin >> stick[i];
            sum += stick[i];
        }
//        qsort(stick, num, sizeof (int), compare);
        for (int n = num - 1; n > 0; n--) {
            if (sum % n == 0 && sum / n >= stick[0]) {
                int r = testlen(sum / n);
                if (r != -1) {
                    cout << r << endl;
                    break;
                }
            }
        }
        cin >> num;
    }
    return 0;
}

int testlen(int targetlen) {
    memset(used, 0, sizeof (int) *64);
    if (concated( 0,  targetlen, 0)) {
        return targetlen;
    }
    return -1;
}

bool concated( int leftlen,  int targetlen, int usednum) {
    if (usednum == num && leftlen == 0) {
        return true;
    }
    if (leftlen == 0) {
        leftlen = targetlen;
    }
    for (int i = 0; i < num; i++) {
        if (used[i] == 1)
            continue;
        if (stick[i] > leftlen)
            continue;
        used[i] = 1;
        if (concated(leftlen - stick[i],  targetlen, usednum + 1)) {
            return true;
        }
        used[i] = 0;
        if (stick[i] == leftlen || leftlen == targetlen) {
            break;
        }
    }
    return false;
}
